package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController     //@ResponseBody + @Controller
public class SetmealController {

    //依赖注入service层
    @Autowired
    private SetmealService setmealService;

    /**
     * c端查询套餐列表
     * Request URL: http://localhost:8081/setmeal/list?categoryId=1538456925895790592&status=1
     * Request Method: GET
     */
    @GetMapping("/setmeal/list")
    public ResultInfo findList(String categoryId, String status){       //获取请求参数
        //1. 调用service层
        List<Setmeal> setmealList = setmealService.findList(categoryId,status);
        //2. 返回响应
        return ResultInfo.success(setmealList);
    }

    /**
     * c端显示套餐信息
     * Request URL: http://localhost:8081/setmeal/dish/1415580119015145474
     * Request Method: GET
     */
    @GetMapping("/setmeal/dish/{id}")
    public ResultInfo showDishMsg(@PathVariable Long id){   //接收RESTful风格的参数
        //1.调用service层
        List<Dish> dishList = setmealService.showDishMsg(id);
        //2.返回响应
        return ResultInfo.success(dishList);
    }

}
